<%
	// example: 
	// <a href="DirectDown.jsp?path=img/&name=test.gif">download image</a> 

	String root = getServletContext().getRealPath("/");
	request.setCharacterEncoding("GB2312");
	String path = request.getParameter("path");
	String name = request.getParameter("name");
	//response.setCharacterEncoding("GB2312");
	response.setContentType("unknown");
	//name = new String(name.getBytes("ISO-8859-1"),"GB2312"); 
	response.addHeader("Content-Disposition", "filename=\"" + name+ "\"");
	//java.io.OutputStream os=null;
	//java.io.FileInputStream fis = null;
    java.io.BufferedInputStream bis = null;
    java.io.BufferedOutputStream bos = null;

	try {
//		os = response.getOutputStream();
	//	fis = new java.io.FileInputStream(root+ path + name);
        bis = new java.io.BufferedInputStream(new java.io.FileInputStream(root+path+name));
        bos = new java.io.BufferedOutputStream(response.getOutputStream());
		
        byte[] buff = new byte[2048];
        int bytesRead;

        while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
            bos.write(buff,0,bytesRead);
        }

    } catch(java.io.IOException e) {
        System.out.println ( "IOException." + e );
    } finally {
        if (bis != null)
            bis.close();
        if (bos != null)
            bos.close();
    }
%>

